/** @jsxImportSource @emotion/react */
import {usePrefixDataTable} from "../../hook/usePrefixData";
import {useThreeColumnView} from "../../hook/useThreeColumnSubr";
import {CCell, Cell, Table, TableBody, TableHead, TableRow, Text} from "customize-easy-ui-component";
import * as React from "react";
import {RepLink, } from "../../common/base";
import {DirectLink} from "../../../routing/Link";
import {Each_ZdSetting, useRep2hTableViewerX} from "../../hook/useRepTableEditor";
import {render工作幅} from "../../tower/craneJj/orcBase";

//正式报告
export const config设备 = [
  [['使用单位', '_$使用单位'],  ],
  [['使用单位地址', '_$使用单位地址'],  ],
  [['设备使用地点', '_$设备使用地点']],
  [['安全管理人员', '安全员'], ['联系电话', '安全员电']],
  [['制造单位名称', '_$制造单位'] ],
  [['施工单位名称',{n:'施工单',t:'B'} ], ],
  [['监控系统生产单位名称','_$监控系统生产单'] ],
  [['监控系统型号', '_$监控系统型号'], ['监控系统编号', '_$监控系统编号'], ],
  [['产品编号', '_$出厂编号'], ['型号规格', '_$型号'] ],
  //性能参数;  #【代码耦合点】 拆分位置
  [['额定起重量','_$额定起重量','t'], ['工作级别','_$工作级别'], ],
  [['跨度','_$跨度','m'], ['生产率','_$生产率','t/h'] ],
  [['工作幅度','_$最大工作幅',render工作幅],  ['额定起重力矩','_$起重力矩','t·m'] ],
  [['起升高度','_$提升高度','m'], ['起升速度','_$起升速','m/min'], ],
  [['大车(横移)速度','_$大车速度','m/min'],['小车(纵移)速度','_$小车速度','m/min']],
];

//正式报告视图用：
export const config报告仪器=[['仪器名称','n',160,],['仪器编号','i',90], ] as Each_ZdSetting[];
/**还是拆解开掉： 避免参数传递麻烦。
 * @param fixed :针对设备概况的主要部分 调整表格跨度。
 * @param ispan :性能参数 有几行的；
 * @param xnFixed: 性能参数开始的 下半部分的布局宽度；
 * */
export const 报告设备详情上mMs= ({orc, rep, config,spIdx,fixed=["6.1%","8%","40%","8.1%","8%","%"],ispan=4,
                                 xnFixed=["4.8%","18.1%","30%","9%","12.2%","10%","%"], gybz }
                                   : { orc: any,rep:any, config:any[],spIdx:number,fixed?:string[],ispan?:number,xnFixed?:string[],gybz?:boolean}
) => {
  const memoTxt=gybz? orc?.概备注 : orc?.大备注;
  //拆分成2个编辑器的
  const config设备上=config.slice(0, spIdx);
  const config设备下=config.slice(spIdx);
  const renderUpper=usePrefixDataTable({config: config设备上, orc, rep, slash:true});
  const [firstPart,_s]=useThreeColumnView({orc, config:config设备下,slash:true,
    embedCol: [ <CCell rowSpan={ispan}>性能参数</CCell> ]});

  const [instrument,] =useRep2hTableViewerX({table:'仪器表', config:config报告仪器, orc, seqCl:'序号'});
  return <React.Fragment>
    <Table id={'Survey'} fixed={fixed}  css={ {borderCollapse: 'collapse' } }  tight  miniw={800}>
      <TableBody>
        <RepLink rep={rep} tag={'Survey'}>
          {renderUpper}
        </RepLink>
      </TableBody>
    </Table>
    <Table fixed={xnFixed}  css={ {borderCollapse: 'collapse' } }  tight  miniw={800}>
      <TableBody>
        <RepLink rep={rep} tag={'Survey'}>
          {firstPart}
        </RepLink>
        <TableRow>
          <CCell colSpan={1}>检验依据</CCell>
          <CCell colSpan={6}>《起重机械安装改造重大修理监督检验规则》（TSG Q7016-2016)及第1号修改单</CCell>
        </TableRow>
        <RepLink rep={rep} ori tag='Instrument'>
          <TableRow>
            <CCell>主要检验仪器设备</CCell>
            <Cell colSpan={6} css={{padding:0}}>
              <Table fixed={ ["4%","25%","21%","4%","25%","%"] }
                     css={ {borderCollapse: 'collapse', height:'fill-available'}}  tight miniw={800}>
                <TableHead>
                  <TableRow>
                    <CCell><Text css={{fontSize:'0.7rem'}}>序号</Text></CCell>
                    <CCell>仪器名称</CCell>
                    <CCell>仪器编号</CCell>
                    <CCell><Text css={{fontSize:'0.7rem'}}>序号</Text></CCell>
                    <CCell>仪器名称</CCell>
                    <CCell>仪器编号</CCell>
                  </TableRow>
                </TableHead>
                <TableBody>
                  {instrument}
                </TableBody>
              </Table>
            </Cell>
          </TableRow>
        </RepLink>
        <DirectLink href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/Conclusion#Conclusion`}>
          <TableRow>
            <CCell>检验结论</CCell><CCell colSpan={6}><Text variant="h1" css={{fontSize:'2.2rem',letterSpacing: '1rem'}}>{orc?.检验结论}</Text></CCell>
          </TableRow>
        </DirectLink>
        <RepLink rep={rep} tag={gybz? 'Survey' : 'Witness'}>
          <TableRow>
            <CCell>备注</CCell>
            <Cell split={true} colSpan={6}><div css={{minHeight: '1rem', whiteSpace: 'pre-wrap'}}>
              {memoTxt ?? '／'}
            </div></Cell>
          </TableRow>
        </RepLink>
      </TableBody>
    </Table>
  </React.Fragment>;
};
